module.exports = ({
    uriName,
    payload,
}) => {
    return {
        data(){
            return {
                uriName,
                payload,
                restClient: require('../restClient')({
                    'uriName': uriName,
                }),
                query: (new URL(window.location.href)).searchParams.get('q'),
            }
        },
        computed: {
            createUrl() {
                return this.restClient.makeUrl() + '/create'
            },
        },
        methods: {
            log(...msg) {
                console.log(...msg)
            },
            handleSearch(text) {
                window.location.href = this.restClient.makeUrl() + '?q=' + text
            },
            handleDelete(id) {
                this.restClient.destroy(id).then(({data}) => {
                    setTimeout(() => {
                        window.location.href = this.restClient.makeUrl()
                    }, 1200)
                })
            },
            makeEditUrl(id) {
                return this.restClient.makeUrl(id) + '/edit'
            },
            makeShowUrl(id) {
                return this.restClient.makeUrl(id)
            },
        }
    }
}